﻿using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FwProject.Web.Shop.FwTagHelper
{
    [HtmlTargetElement("boolRadio")]
    public class RadioTagHelper: TagHelper
    {
        [HtmlAttributeName("asp-value")]
        public bool SelectedValue { get; set; }

        [HtmlAttributeName("asp-id")]
        public string Id { get; set; }

        [HtmlAttributeName("asp-name")]
        public string Name { get; set; }


        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var value = context.AllAttributes["value"]?.Value as string;
            var radio = new TagBuilder("input");
            radio.TagRenderMode = TagRenderMode.SelfClosing;
            radio.Attributes.Add("name", Name);
            radio.Attributes.Add("Id", Id);
            radio.Attributes.Add("value", "true");
            radio.Attributes.Add("title", "是");
            radio.Attributes.Add("type", "radio");

            var radio2 = new TagBuilder("input");
            radio2.TagRenderMode = TagRenderMode.SelfClosing;
            radio2.Attributes.Add("name", Name);
            radio2.Attributes.Add("Id", Id);
            radio2.Attributes.Add("value", "false");
            radio2.Attributes.Add("title", "否");
            radio2.Attributes.Add("type", "radio");

            if (SelectedValue)
            {
                radio.Attributes.Add("checked", "checked");
            }
            else
            {
                radio2.Attributes.Add("checked", "checked");
            }
            output.Content.AppendHtml(radio);
            output.Content.AppendHtml(radio2);


        }
    }


}
